package com.zp.enums;

import cn.hutool.core.util.StrUtil;
import lombok.Getter;

import java.util.HashMap;
import java.util.Map;

/**
 * 空间角色枚举
 */
@Getter
public enum SpaceUserRoleEnum {
    VIEWER("浏览者", "viewer"),
    EDITOR("编辑者", "editor"),
    ADMIN("管理员", "admin");

    private final String text;
    private final String value;

    SpaceUserRoleEnum(String text, String value) {
        this.text = text;
        this.value = value;
    }

    private static final Map<String, SpaceUserRoleEnum> VALUE_MAP = new HashMap<>();

    static {
        for (SpaceUserRoleEnum anEnum : SpaceUserRoleEnum.values()) {
            VALUE_MAP.put(anEnum.value, anEnum); // anEnum.value: viewer/editor/admin
        }
    }

    /**
     * 根据 value 获取枚举对象
     *
     * @param value viewer/editor/admin
     * @return SpaceUserRoleEnum
     */
    public static SpaceUserRoleEnum getEnumByValue(String value) {
        if (StrUtil.isBlank(value)) {
            return null;
        }
        return VALUE_MAP.get(value);
    }
}
